<template>
    <div>
        <span class="head-title">
            <!-- {{ store.appFront.obituary }} {{ store.appFront.managementSystem }} -->
            OVO 后台管理
        </span>

        <span style="float: right;
                                                    margin-right:30px;
                                                    margin-top: 5px;
                                                    ">

            <div class="head-title-span" style="line-height: 40px;margin-right: 20px;
                                            margin-top: 5px;
                                            ">
                <SwitchLanguage />
            </div>

            <el-popover popper-class="info-popover" popper-style="height: 470px;" placement="left" width="220px"
                trigger="hover">
                <template #default>

                    <div class="info-box">
                        <div class="info">{{ store.appFront.nickname }}：{{ userInfo.nickname }}</div>
                        <div class="info">{{ store.appFront.phone }}：{{ userInfo.phone }}</div>
                        <div class="info">{{ store.appFront.email }}：{{ userInfo.email }}</div>
                        <el-divider>{{ store.appFront.role.toUpperCase() }}</el-divider>
                        <div style="height: 200px;position: relative;">
                            <el-row style="position: absolute;width: 100%;top:50%;transform: translateY(-50%);">

                                <div 
                                v-for="item in userInfo.roles"
                                :key="item.code"
                                style="text-align: center;width: 100%;">
                                    <el-tag class="role-tag" type="info">{{ item.name }}</el-tag>
                                </div>

                            </el-row>
                        </div>
                        <el-divider></el-divider>
                        <el-button type="danger" style="width: 100%;">{{ store.appFront.logOut }}</el-button>

                    </div>
                </template>
                <template #reference>

                    <span class="head-title-span" style="vertical-align: top;">
                        <el-avatar src="https://avatars.githubusercontent.com/u/20411997?v=4">
                        </el-avatar>
                    </span>
                </template>
            </el-popover>

        </span>
    </div>
</template>


<script lang="ts" setup>
import SwitchLanguage from '@/components/SwitchLanguage.vue';
import { useStore } from '@/stores/counter';
import $kt from '@/vueKantboot';
import { ref } from 'vue';

const store = useStore();

const userInfo = ref({
    nickname: '',
    phone: '',
    email: '',
    roles: [{
        "code": "user",
        "gmtModified": 1681145855686,
        "name": "普通用戶"
    }],
});

/**
 * 获取用户信息
 */
const getUserInfo = () => {
    $kt.request.request({
        url: '/system/user/getSelf',
        method: 'post',
    }).then((res: any) => {
        userInfo.value = res.data.data;
    });
}

getUserInfo();
</script>

<style lang="scss" scoped>
.role-tag {
    margin: 5px;
}

.info-box {
    width: 200px;
    height: 100px;
    padding: 10px;
    box-sizing: border-box;

    .info {
        font-size: 14px;
        color: #999999;
        line-height: 30px;
        // 超出隐藏
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;

    }
}

.head {
    background-color: #ffffff;
    box-sizing: border-box;
    border: 2px solid #ebeef5;
    height: 55px;
    position: relative;
    width: 100%;
    z-index: 999;
    min-width: 600px;


    .head-title {
        font-size: 14px;
        font-weight: 700;
        color: #333333;
        line-height: 55px;
        padding-left: 20px;
    }

    .head-title-span {
        display: inline-block;
        font-weight: 700;
        color: #333333;
        line-height: 55px;
    }

}

.menu-box {
    position: relative;
    float: left;
    width: 240px;
    height: calc(100vh - 55px);
}

.body-box {

    width: calc(100% - 240px);
    height: calc(100vh - 70px);
    float: left;
    position: absolute;
    min-width: 500px;
    left: 240px;

    .body-box-header {
        position: relative;
        width: 100%;
        height: 40px;
        box-sizing: border-box;
        border-bottom: none;
        box-sizing: border-box;
        padding: 0 20px 0 20px;
        margin-top: 10px;

        .body-box-headerb-readcrumb {
            font-size: 16px;
            padding: 16px 0 16px 16px;
            border-radius: 10px;
            border: 2px solid #ebeef5;
            box-sizing: border-box;
            color: #999999;
            background-color: #ffffff;
        }
    }

    .body-box-router-view {
        position: relative;
        width: 100%;
        height: calc(100% - 40px);
        padding: 20px;
        box-sizing: border-box;
    }

}
</style>